package insight.google.game.era.client.proxy;

import insight.google.game.era.bo.GameUser;
import insight.google.game.era.bo.card.CharacterCard;
import insight.google.game.era.bo.card.GameCard;
import insight.google.game.era.bo.card.RoleCard;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;

import org.directwebremoting.proxy.ScriptProxy;

public class PlayerClientProxyImpl implements PlayerClientProxy {

    /**
	 * 
	 */
	protected static PlayerClientProxy playerClientProxy;
    
    public static PlayerClientProxy getInstance(){
        if(playerClientProxy == null){
            playerClientProxy = new PlayerClientProxyImpl();
        }
        return playerClientProxy;
    }
    
	public void healthUpdate(ScriptProxy userProxy, String jsComponenetId,
			int count) {
		// TODO Auto-generated method stub

	}

	public void playTurnNotification(ScriptProxy userProxy,
			String jsComponenetId) {
		// TODO Auto-generated method stub

	}

	public void dispatchCard(ScriptProxy userProxy, String jsComponentId,
			Collection<GameCard> cards) {
		// TODO Auto-generated method stub
		userProxy.addFunctionCall("componentExecFunctionWithCall",jsComponentId,"dispatchCards", cards);
        //debug
        System.out.println("dispatchCard card size : " + cards.size() + "; card :" + cards.toString());
	}

	public void recieveCard(ScriptProxy userProxy, String jsComponentId,
			Collection<GameCard> cards) {
		// TODO Auto-generated method stub
		userProxy.addFunctionCall("componentExecFunctionWithCall",jsComponentId,"receiveCard", cards);
	}

    public void attackCardPolicyExe(ScriptProxy userProxy, String jsComponentId, String matchMethod, String orgUser, String cardName) {
        // TODO Auto-generated method stub
        String[] param = new String[2];
        param[0] = orgUser;
        param[1] = cardName;
        userProxy.addFunctionCall("componentExecFunction",jsComponentId,matchMethod, param);
    }

    public void duelCardPolicyExe(ScriptProxy userProxy, String jsComponentId, String matchMethod, String orgUser, String cardType) {
        // TODO Auto-generated method stub
        String[] param = new String[2];
        param[0] = orgUser;
        param[1] = cardType;
        userProxy.addFunctionCall("componentExecFunction",jsComponentId,matchMethod, param);
    }

    public void milkCardPolicyExe(ScriptProxy userProxy, String jsComponentId, String matchMethod, int count) {
        // TODO Auto-generated method stub
        userProxy.addFunctionCall("componentExecFunctionWithCall",jsComponentId,matchMethod, count);
    }

    public void readyToPlay(ScriptProxy userProxy, String jsComponentId) {
        // TODO Auto-generated method stub
        userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "readyToPlay");
    }

    public void setActive(ScriptProxy userProxy, String jsComponentId, boolean isActive) {
        // TODO Auto-generated method stub
        userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "setActive", isActive);
    }

    public void healLife(ScriptProxy userProxy, String jsComponentId, int count) {
        // TODO Auto-generated method stub
        userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "healLife", count);
    }

	@Override
	public void recievePlayerCard(ScriptProxy userProxy, String jsComponentId,
			List<GameCard> cardList) {
		userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "receiveCard", cardList);
		
	}

	@Override
	public void dispatchRoleCard(ScriptProxy userProxy, String jsComponentId,
			RoleCard card, long dataVersion) {
		// TODO Auto-generated method stub
        Object[] param = new Object[2];
        param[0] = card;
        param[1] = dataVersion;
		userProxy.addFunctionCall("componentExecFunction", jsComponentId, "recieveRoleCard", param);
		//userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "recieveRoleCard", card);
	}

	@Override
	public void showRoleCard(ScriptProxy userProxy, String jsComponentId,
			GameUser kingUser) {
		userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "setUsergRoleToShow", kingUser);
		
	}

	@Override
	public void dispatchCharacterCard(ScriptProxy userProxy,
			String jsComponentId, CharacterCard card, long dataVersion) {
		// TODO Auto-generated method stub
        Object[] param = new Object[2];
        param[0] = card;
        param[1] = dataVersion;
		userProxy.addFunctionCall("componentExecFunction", jsComponentId, "recieveCharacterCard", param);
	}

	@Override
	public void showCharacterCardToUser(ScriptProxy userProxy,
			String jsComponentId, GameUser user) {
		// TODO Auto-generated method stub
		userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "setUserCharacterToShow", user);
	}

	@Override
	public void displayLifeCount(ScriptProxy userProxy, String jsComponentId,
			GameUser user) {
		userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "setLifeCountToShow", user);
		
	}

	@Override
	public void setActiveCard(ScriptProxy userProxy, String jsComponentId,
			List<String> activeCards) {
		// TODO Auto-generated method stub
		userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "setActiveCards", activeCards);
	}

	@Override
	public void enablePolicyExec(ScriptProxy userProxy, String jsComponentId,
			GameUser user) {
		// TODO Auto-generated method stub
		userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "selectPolicyCards", user);
	}

	@Override
	public void registerAttackableUser(ScriptProxy userProxy,
			String jsComponentId, Collection<GameUser> user) {
		// TODO Auto-generated method stub
		userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "registerAttackableUser", user);
	}

	@Override
	public void selectDropCard(ScriptProxy userProxy, String jsComponentId, int cardCount) {
		// TODO Auto-generated method stub
		userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "selectDropCards", cardCount);
	}

	@Override
	public void finishDropCard(ScriptProxy userProxy, String jsComponentId) {
		// TODO Auto-generated method stub
		userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "finishDropCard");
	}

	@Override
	public void finishExecPolicy(ScriptProxy userProxy, String jsComponentId) {
		// TODO Auto-generated method stub
		userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "finishExecPolicy");
	}
    
	@Override
	public void removeClientSelectedCard(ScriptProxy userProxy, String jsComponentId) {
		// TODO Auto-generated method stub
		userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "removeSelectedCard");
	}

	@Override
	public void replaceEquipmentCard(ScriptProxy userProxy,
			String jsComponentId, GameCard card) {
		// TODO Auto-generated method stub
		userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "replaceEquipmentCard", card);
	}

	@Override
	public void removeClientCard(ScriptProxy userProxy, String jsComponentId) {
		// TODO Auto-generated method stub
		userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "removeClientCard");
	}

	@Override
	public void showCardToUser(ScriptProxy userProxy, String jsComponentId,
			HashMap<String, String> data) {
		 userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "setCardCountToShow", data);
		
	}

	@Override
	public void updateUIforProfile(ScriptProxy userProxy, String jsComponentId,
			Object data) {

		userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "updateSelfProfileInfo", data);
	}

	@Override
	public void notifyOtherUserForUpdatedProfile(ScriptProxy userProxy,
			String jsComponentId, Object data) {
		// TODO Auto-generated method stub
		userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "updateOtheUsersProfile", data);
	}

	@Override
	public void askCardDiscardExec(ScriptProxy userProxy, String jsComponentId,
			String matchMethod, String orgUser, String cardType) {
		// TODO Auto-generated method stub
        String[] param = new String[2];
        param[0] = orgUser;
        param[1] = cardType;
        userProxy.addFunctionCall("componentExecFunction",jsComponentId,matchMethod, param);
	}

	@Override
	public void askSaveSelfExec(ScriptProxy userProxy, String jsComponentId) {
		// TODO Auto-generated method stub
		userProxy.addFunctionCall("componentExecFunctionWithCall",jsComponentId,"askSaveSelfExec", "");
	}

	@Override
	public void clearClientByDead(ScriptProxy userProxy, String jsComponentId) {
		// TODO Auto-generated method stub
		userProxy.addFunctionCall("componentExecFunctionWithCall",jsComponentId,"clearClientByDead", "");
	}

	@Override
	public void refreshEquipmentCard(ScriptProxy userProxy, String jsComponentId,
			List<GameCard> cardList) {
		userProxy.addFunctionCall("componentExecFunctionWithCall", jsComponentId, "refreshEquipmentCard", cardList);
		
	}

}
